package cn.com.bluemoon.daps.domp.api;

import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.FeignApiRespBean;
import cn.com.bluemoon.daps.common.domain.UserInfoHolder;
import cn.com.bluemoon.daps.domp.api.factory.RemoteUserServiceFallbackFactory;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @author Lilike on 2023/1/2
 */
@FeignClient(ServiceNameConstants.DapsApiSystem.PROD_SERVICE)
@RequestMapping(ServiceNameConstants.DapsApiSystem.BASE_URI + "/user")
@Api(tags = "FeignClient服务-蓝数通bd-user-service")
public interface LocalUserService {

    /**
     * 发现token为空（多个空）出现拿到用户信息情况进行修复
     */
    @RequestMapping("/isLoginUser")
    String isLoginUser(@RequestParam(name = "token") String token);



    /**
     * 通过userId获得用户信息
     */
    @RequestMapping("/getUserInfoById")
    public List<Map<String, Object>> getUserInfoById(@RequestParam(name = "userId")String userId);

    /**
     * 用户信息
     */
    default UserInfoHolder.UserInfo getUserInfoByUserId(String userId) {
        List<Map<String, Object>> userInfoById = getUserInfoById(userId);
        if (userInfoById != null) {
            Map<String, Object> map = userInfoById.stream().findFirst().orElse(Collections.emptyMap());
            UserInfoHolder.UserInfo userInfo = new UserInfoHolder.UserInfo();
            userInfo.setAccount(map.getOrDefault("ID", "").toString());
            userInfo.setMobile(map.getOrDefault("MOBILE", "").toString());
            userInfo.setUserName(map.getOrDefault("USER_NAME", "").toString());
            userInfo.setEmail(map.getOrDefault("EMAIL", "").toString());
            return userInfo;
        }
        return null;
    }



    /**
     * 用户登陆
     *
     * @param userName 用户名
     * @param passWord 密码
     * @throws Exception 注意：页面传过来的密码为AES加密后的密码，发送给天使的密码为DES加密后的密码，
     *                   保存在domp数据库中的的密码为md5加密后的密码
     *                   domp默认密码为tR4362do
     */
    @RequestMapping(value = "/login")
    String login(@RequestParam("userName") String userName, @RequestParam("passWord") String passWord);


}
